package com.数据结构;

public class MydoubleLinkedList {
    private DNode first;
    private DNode last;
    private int size;

    public void addFirst(Object o){
        DNode dNode = new DNode(o);
        if(size == 0){
            first = dNode;
            last = dNode;
            size += 1;
        }else {
            first.setPrev(dNode);
            dNode.setNext(first);
            first = dNode;
            size += 1;
        }
    }

    public void addLast(Object o){
        DNode dNode = new DNode(o);
        if(size == 0){
            first = dNode;
            last = dNode;
            size += 1;
        }else{
            last.setNext(dNode);
            dNode.setPrev(last);
            last = dNode;
            size += 1;
        }
    }
}

class DNode{
    private Object o;
    private DNode prev;
    private DNode next;

    public DNode(Object o) {
        this.o = o;
    }

    public Object getO() {
        return o;
    }

    public void setO(Object o) {
        this.o = o;
    }

    public DNode getPrev() {
        return prev;
    }

    public void setPrev(DNode prev) {
        this.prev = prev;
    }

    public DNode getNext() {
        return next;
    }

    public void setNext(DNode next) {
        this.next = next;
    }


}
